package cn.mw.cmdb.enums;

import cn.hutool.json.JSONArray;
import cn.mw.components.mongodb.exception.BusinessException;
import com.alibaba.fastjson.JSONObject;

public enum BusynessSystemUtilizationEnum {
    CPU("CPU利用率", "CPU_UTILIZATION"),
    MEMORY("内存利用率", "MEMORY_UTILIZATION"),
    INTERFACE_TRAFFIC("接口流量利用率", "INTERFACE_IN_UTILIZATION"),
    INTERFACE_IN("每秒接收流量", "MW_INTERFACE_IN_TRAFFIC"),
    INTERFACE_OUT("每秒发送流量", "MW_INTERFACE_OUT_TRAFFIC"),
    DISK("磁盘利用率", "MW_DISK_UTILIZATION");

    private final String chineseName;
    private final String englishName;

    private static final String KEY = "systemUtilization";

    BusynessSystemUtilizationEnum(String chineseName, String englishName) {
        this.chineseName = chineseName;
        this.englishName = englishName;
    }

    public String getChineseName() {
        return chineseName;
    }

    public String getEnglishName() {
        return englishName;
    }

    public static BusynessSystemUtilizationEnum getCNameByEName(String englishName) {
        for (BusynessSystemUtilizationEnum statisticalEnum : BusynessSystemUtilizationEnum.values()) {
            if (statisticalEnum.getEnglishName().equals(englishName)) {
                return statisticalEnum;
            }
        }
        throw new BusinessException("");
    }

    public static JSONObject getAll() {
        JSONObject object = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (BusynessSystemUtilizationEnum value : BusynessSystemUtilizationEnum.values()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("chineseName", value.getChineseName());
            jsonObject.put("englishName", value.getEnglishName());
            jsonArray.add(jsonObject);
        }
        object.put(KEY, jsonArray);
        return object;
    }
}
